#ifndef _COMPOSITE_H_
#define _COMPOSITE_H_

#include <vector>
#include <cstddef>

class Component
{
public:
    Component();
    virtual ~Component();
    
public:
    virtual void Operation() = 0;
    
    // 提供缺省行为
    virtual void Add(Component* com);
    virtual void Remove(Component* com);
    virtual Component* GetChild(int index);
};

class Leaf : public Component
{
public:
    Leaf();
    ~Leaf();
    
public:
    virtual void Operation();   
};

class Composite : public Component
{
public:
    Composite();
    ~Composite();
    
public:
    virtual void Operation();
    virtual void Add(Component* com);
    virtual void Remove(Component* com);
    virtual Component* GetChild(size_t index);
    
private:
    std::vector<Component*> com_vec_;
};

#endif // _COMPOSITE_H_